package com.itheima.mqConsumer;

import com.itheima.config.RabbitMQConfig;
import com.itheima.config.ThreadPoolConfig;
import com.itheima.service.UserLikeMessageService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Map;

/**
 * <h1>mq消费者类</h1>
 *
 * @author <a href="515857087@qq.com">叶世铭</a>
 * @since 2022/10/28
 */
@Component
@RabbitListener(queues = RabbitMQConfig.RABBITMQ_DEMO_TOPIC)
public class RabbitmqDemoConsumer {

    @Resource
    private UserLikeMessageService userLikeMessageService;
    @Resource
    private ThreadPoolConfig threadPoolConfig;

    @RabbitHandler
    public void process(Map<String, String> map) {
        threadPoolConfig.asyncExecutor().execute(() -> {
            userLikeMessageService.mqOperation(Integer.valueOf(map.get("messageId")), map.get("userId"), map.get("operation"));
            System.out.println(map);
            System.out.println("消费者消费RabbitmqDemo中的消息" + map.toString());
            System.out.println("消费者结束时间：" + LocalDateTime.now());
        });
    }
}
